package com.dz.finance.biz.service.impl;

import com.dz.finance.biz.constant.MsgConstant;
import com.dz.finance.common.constant.SystemConstant;
import com.dz.finance.biz.entity.Member;
import com.dz.finance.biz.mapper.MemberMapper;
import com.dz.finance.biz.service.MemberService;
import com.dz.finance.common.exception.BizException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author: DengHaoQi
 * @date: 2024/5/31 19:29
 * @description:
 */

@Slf4j
@Service
@RequiredArgsConstructor
public class MemberServiceImpl implements MemberService {


    private final MemberMapper memberMapper;


    /*
     * 会员注册
     * */
    @Override
    public Long reg(Long tenantId) {
        Member member = new Member();
        member.setTenantId(tenantId);
        member.setSysRoleIds("[" + SystemConstant.ROLE_MEMBER + "]"); // 赋予普通会员角色
        member.initDefault();
        int row = memberMapper.insert(member);
        if (row == 0) {
            log.error("会员注册失败");
            throw new BizException(MsgConstant.MEMBER_REG_FAIL);
        }
        return member.getId();
    }


    /*
     * 根据member中的条件查询
     * */
    @Override
    public Member getMember(Member member) {
        return memberMapper.selectMember(member);
    }
}
